namespace UnitTests
{
    using System;
    using System.Collections.Specialized;
    using FormStateKeeper;
    using NUnit.Framework;
    using Ploeh.AutoFixture;
    using UnitTests.Foundation;

    [TestFixture]
    public class FormStateTests : BaseTestFixture
    {
        [Test]
        public void GetCurrent_NullContext_ReturnsNull()
        {
            Assert.Null(FormState.GetCurrent(null));
        }

        [Test]
        public void SetCurrent_NullContext_Pass()
        {
            FormState.SetCurrent(null, null);
        }

        [Test]
        public void Create_NullContext_ReturnsNull()
        {
            Assert.Null(FormState.Create(null));
        }

        [Test]
        public void Create_EmptyForm_ReturnsFormStateWithEmptyForm()
        {
            using (var context = new TestContextBuilder<WebTestContext>().Create())
            {
                FormState res = FormState.Create(context.HttpContextMock.Object);
                Assert.AreEqual(0, res.Form.Count);
            }
        }

        [Test]
        public void Create_ValueInForm_ReturnsFormStateWithValueInForm()
        {
            using (var context = new TestContextBuilder<WebTestContext>().Create())
            {
                var auto = this.GetNewAutoFixture();
                string name = auto.CreateAnonymous<string>();
                string value = auto.CreateAnonymous<string>();
                context.RequestMock.Object.Form.Add(name, value);
                
                FormState res = FormState.Create(context.HttpContextMock.Object);
                
                Assert.AreEqual(1, res.Form.Count);
                Assert.AreEqual(value, res.Form[name]);
            }
        }
    }
}